package controller

import (
	"StrayAnimals/internal/service"
	"github.com/gin-gonic/gin"
)

func GetAnimalById(c *gin.Context) {
	animalId := c.Query("id")

	if animalId == "" {
		c.JSON(400, gin.H{
			"code":    400,
			"message": "动物 ID 不能为空",
		})
		return
	}

	animal, err := service.GetAnimalByIdFromSQL(animalId)
	if err != nil {
		c.JSON(500, gin.H{
			"code":    500,
			"message": "查找单个动物失败" + err.Error(),
		})
		return
	}

	c.JSON(200, gin.H{
		"code": 200,
		"data": animal,
	})
}

func GetAnimalList(c *gin.Context) {
	animals, err := service.GetAnimalListFromSQL()
	if err != nil {
		c.JSON(500, gin.H{
			"code":    500,
			"message": "查找动物列表失败" + err.Error(),
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"data": animals,
	})
}
